/* * Author: Todd Motto | @toddmotto * URL: html5blank.com | @html5blank * Custom functions, support, custom post types and more. */ /*------------------------------------*\ External Modules/Files \*------------------------------------*/ // Load any external files you have here /*------------------------------------*\ Theme Support \*------------------------------------*/ $GLOBALS['localUrl'] = "apomaxx.lokal"; $GLOBALS['lazyPlaceholderImg'] = get_template_directory_uri().'/assets/img/placeholder.gif'; if(have_rows('global_ids', 'option')){ while(have_rows('global_ids', 'option')){ the_row(); if(function_exists('icl_object_id')){ // INKLUSIVE WPML $GLOBALS['ownId'][get_sub_field('name')] = icl_object_id(get_sub_field('id'), get_sub_field('typ'), true, ICL_LANGUAGE_CODE); } else { // Normal, ohne WPML $GLOBALS['ownId'][get_sub_field('name')] = get_sub_field('id'); } } } if (!isset($content_width)) { $content_width = 900; } if (function_exists('add_theme_support')) { // Add Menu Support add_theme_support('menus'); // Add Thumbnail Theme Support add_theme_support('post-thumbnails'); add_image_size('large', 700, '', true); // Large Thumbnail add_image_size('medium', 250, '', true); // Medium Thumbnail add_image_size('small', 120, '', true); // Small Thumbnail add_image_size('biggest', 3000, '', true); // Enables post and comment RSS feed links to head add_theme_support('automatic-feed-links'); // Localisation Support load_theme_textdomain('html5blank', get_template_directory() . '/languages'); } function replace_uploaded_image($image_data) { // if there is no large image : return if (!isset($image_data['sizes']['biggest'])) return $image_data; // paths to the uploaded image and the large image $upload_dir = wp_upload_dir(); $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file']; // $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file']; // ** This only works for new image uploads - fixed for older images below. $current_subdir = substr($image_data['file'],0,strrpos($image_data['file'],"/")); $large_image_location = $upload_dir['basedir'] . '/'.$current_subdir.'/'.$image_data['sizes']['biggest']['file']; // delete the uploaded image unlink($uploaded_image_location); // rename the large image rename($large_image_location,$uploaded_image_location); // update image metadata and return them $image_data['width'] = $image_data['sizes']['biggest']['width']; $image_data['height'] = $image_data['sizes']['biggest']['height']; unset($image_data['sizes']['biggest']); return $image_data; } add_filter('wp_generate_attachment_metadata','replace_uploaded_image'); /*------------------------------------*\ Functions \*------------------------------------*/ // HTML5 Blank navigation function html5blank_nav($location, $depth = 0, $zusatz = '', $before = '') { wp_nav_menu( array( 'theme_location' => $location, 'menu' => '', 'container' => 'div', 'container_class' => 'menu-{menu slug}-container', 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => '', 'echo' => true, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => $before, 'link_after' => '', 'items_wrap' => '
' . $output . '
'; echo $output; } // Custom View Article link to Post function html5_blank_view_article($more) { global $post; return '... ' . __('View Article', 'html5blank') . ''; } // Remove Admin bar function remove_admin_bar() { if (is_user_logged_in()) { return false; } } // Remove 'text/css' from our enqueued stylesheet function html5_style_remove($tag) { return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag); } // Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail function remove_thumbnail_dimensions($html) { $html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html); return $html; } // Custom Gravatar in Settings > Discussion function html5blankgravatar($avatar_defaults) { $myavatar = get_template_directory_uri() . '/assets/img/gravatar.png'; $avatar_defaults[$myavatar] = "Custom Gravatar"; return $avatar_defaults; } // Threaded Comments function enable_threaded_comments() { if (!is_admin()) { if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) { wp_enqueue_script('comment-reply'); } } } /*------------------------------------*\ Actions + Filters + ShortCodes \*------------------------------------*/ // Add Actions add_action('init', 'html5blank_styles'); // Add Conditional Page Scripts add_action('get_header', 'enable_threaded_comments'); // Enable Threaded Comments add_action('wp_enqueue_scripts', 'html5blank_header_scripts'); // Add Theme Stylesheet add_action('init', 'register_html5_menu'); // Add HTML5 Blank Menu //add_action('init', 'create_post_type_html5'); // Add our HTML5 Blank Custom Post Type, Demo (Commented out by Default) add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head() add_action('init', 'html5wp_pagination'); // Add our HTML5 Pagination // Remove Actions remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file. remove_action('wp_head', 'index_rel_link'); // Index link remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Display relational links for the posts adjacent to the current post. remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); // Add Filters add_filter('avatar_defaults', 'html5blankgravatar'); // Custom Gravatar in Settings > Discussion add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build) add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar add_filter('widget_text', 'shortcode_unautop'); // Removetags in Dynamic Sidebars (better!) add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding
tags in Excerpt (Manual Excerpts only) add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only) add_filter('excerpt_more', 'html5_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts add_filter('show_admin_bar', 'remove_admin_bar'); // Remove Admin bar add_filter('style_loader_tag', 'html5_style_remove'); // Remove 'text/css' from enqueued stylesheet add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images // Remove Filters remove_filter('the_excerpt', 'wpautop'); // Remove
tags from Excerpt altogether /*------------------------------------*\ herrlich Media Functions \*------------------------------------*/ // Add LESS Support for wp_register_styles // http://x3graphics.com/tutorials/wordpress/adding-less-css-to-wordpress function enqueue_less_styles($tag, $handle) { global $wp_styles; $match_pattern = '/\.less$/U'; if (preg_match($match_pattern, $wp_styles -> registered[$handle] -> src)) { $tag = preg_replace("/='stylesheet'/", "='stylesheet/less'", $tag); } return $tag; } add_filter('style_loader_tag', 'enqueue_less_styles', 5, 2); // Custom Admin Backend Login function LB_custom_login_style() { echo ''; } add_action('login_enqueue_scripts', 'LB_custom_login_style'); function LB_login_logo_url() { return 'http://herrlich.media'; } add_filter('login_headerurl', 'LB_login_logo_url'); function LB_login_logo_title() { return 'Powered by herrlich media'; } add_filter('login_headertitle', 'LB_login_logo_title'); function remove_wp_logo() { global $wp_admin_bar; $wp_admin_bar -> remove_menu('wp-logo'); } add_action('wp_before_admin_bar_render', 'remove_wp_logo'); // Security: Hide Usernames from Classes function andys_remove_comment_author_class($classes) { foreach ($classes as $key => $class) { if (strstr($class, "comment-author-")) { unset($classes[$key]); } } return $classes; } add_filter('comment_class', 'andys_remove_comment_author_class'); class WP_HTML_Compression { // Settings protected $compress_css = true; protected $compress_js = true; protected $info_comment = true; protected $remove_comments = true; // Variables protected $html; public function __construct($html) { if (!empty($html)) { $this -> parseHTML($html); } } public function __toString() { return $this -> html; } protected function bottomComment($raw, $compressed) { $raw = strlen($raw); $compressed = strlen($compressed); $savings = ($raw - $compressed) / $raw * 100; $savings = round($savings, 2); // return ''; } protected function minifyHTML($html) { $pattern = '/<(?